﻿Imports BUS
Imports DTO

Public Class TraCuuSach

    Private sachCrt As New SachCrt
   




    Private Sub CheckBoxTacGia_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBoxTacGia.CheckedChanged
        txttacgia.Enabled = CheckBoxTacGia.Checked

    End Sub

    Private Sub CheckBoxnhaxuatban_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBoxnhaxuatban.CheckedChanged
        cbbNhaXuatBan.Enabled = CheckBoxnhaxuatban.Checked
    End Sub


    Private Sub CheckBoxNamXuatBan_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBoxNamXuatBan.CheckedChanged
        dtpNamXuatBan.Enabled = CheckBoxNamXuatBan.Checked
    End Sub

    Private Sub CheckBoxTheLoaiSach_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBoxTheLoaiSach.CheckedChanged
        cbbtheLoaisach.Enabled = CheckBoxTheLoaiSach.Checked
    End Sub


    Private Sub CheckBoxNgaynhap_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBoxNgaynhap.CheckedChanged
        DateTimePickerngaynhap.Enabled = CheckBoxNgaynhap.Checked
    End Sub


    Private Sub CheckBoxTinhTrang_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBoxTinhTrang.CheckedChanged
        cbbTinhTrang.Enabled = CheckBoxTinhTrang.Checked
    End Sub

    Private Sub CheckBoxtrigia_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBoxtrigia.CheckedChanged
        nudtrigiatu.Enabled = CheckBoxtrigia.Checked
        nudtrigiaden.Enabled = CheckBoxtrigia.Checked
    End Sub


    Private Sub CheckBoxKhoangCachXuatBan_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBoxKhoangCachXuatBan.CheckedChanged
        txtKhoangCachXB.Enabled = CheckBoxKhoangCachXuatBan.Checked
    End Sub

    Private Sub CheckBoxnhanvien_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBoxnhanvien.CheckedChanged
        txtnhanvien.Enabled = CheckBoxnhanvien.Checked
    End Sub
    Private Sub LoadTheLoai()
        Dim tlBus As New TheLoaiBUS

        Dim ds As List(Of TheLoaiDTO)
        ds = tlBus.Laytheloai()
        cbbtheLoaisach.DataSource = ds
        cbbtheLoaisach.ValueMember = "MaTheLoai"
        cbbtheLoaisach.DisplayMember = "TenTheLoai"
    End Sub

    Private Sub CapNhatTieuChiTraCuu(ByVal bUpdate As Boolean)
        If (bUpdate) Then
            If (txtmasach.Text <> "") Then
                sachCrt.MaSach = Integer.Parse(txtmasach.Text)
            Else
                sachCrt.MaSach = 0
            End If
            sachCrt.TenSach = txttensach.Text
            sachCrt.TacGia = txttacgia.Text
            sachCrt.NhaXuatBan = cbbNhaXuatBan.SelectedText
            sachCrt.NamXuatBan = dtpNamXuatBan.Value
            sachCrt.TriGiaTu = nudtrigiatu.Value
            sachCrt.TriGiaDen = nudtrigiaden.Value
            sachCrt.KhoangCachXuatBan = txtKhoangCachXB.Text
            sachCrt.MaTheLoai = cbbtheLoaisach.SelectedValue
            sachCrt.MaNhanVien = txtnhanvien.Text
            sachCrt.MaTinhTrang = cbbTinhTrang.SelectedValue
            sachCrt.NgayNhap = dtpNamXuatBan.Value

            sachCrt.CheckMaTheLoai = CheckBoxTheLoaiSach.Checked
            sachCrt.CheckTacGia = CheckBoxTacGia.Checked
            sachCrt.CheckTriGia = CheckBoxtrigia.Checked
            sachCrt.CheckNhaXuatBan = CheckBoxnhaxuatban.Checked
            sachCrt.CheckNamXuatBan = CheckBoxNamXuatBan.Checked
            sachCrt.CheckNgayNhap = CheckBoxNgaynhap.Checked
            sachCrt.CheckMaTinhTrang = CheckBoxTinhTrang.Checked
            sachCrt.CheckMaNhanVien = CheckBoxnhanvien.Checked
            sachCrt.CheckKhoangCachXuatBan = CheckBoxKhoangCachXuatBan.Checked
        Else
            If sachCrt.MaSach <> 0 Then
                txtmasach.Text = sachCrt.MaSach.ToString()

            End If
            txttensach.Text = sachCrt.TenSach
            txttacgia.Text = sachCrt.TacGia
            txtnhanvien.Text = sachCrt.MaNhanVien
            txtKhoangCachXB.Text = sachCrt.KhoangCachXuatBan
            CheckBoxNamXuatBan.Checked = sachCrt.CheckNamXuatBan
            CheckBoxTacGia.Checked = sachCrt.CheckTacGia
            CheckBoxnhanvien.Checked = sachCrt.CheckMaNhanVien
            CheckBoxKhoangCachXuatBan.Checked = sachCrt.KhoangCachXuatBan
            CheckBoxtrigia.Checked = sachCrt.CheckTriGia
            CheckBoxNgaynhap.Checked = sachCrt.CheckNgayNhap
            CheckBoxTheLoaiSach.Checked = sachCrt.CheckMaTheLoai
            CheckBoxTinhTrang.Checked = sachCrt.CheckMaTinhTrang

        End If


    End Sub


    Private Sub TraCuuSach_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Try
            LoadTheLoai()
            sachCrt = New SachCrt()
            CapNhatTieuChiTraCuu(False)
            Dim dtSach As New DataTable()
            DataGridViewSach.DataSource = dtSach

        Catch ex As Exception
            MessageBox.Show(ex.Message)

        End Try
    End Sub

    Private Sub btntracua_tcsach_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btntracua_tcsach.Click
        Try
            CapNhatTieuChiTraCuu(True)
            Dim sachBus As New SachBUS()
            Dim dtSach As DataTable
            dtSach = sachBus.TimKiem(sachCrt)
            DataGridViewSach.DataSource = dtSach
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub

    Private Sub btnthoat_tcsach_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnthoat_tcsach.Click
        Close()
    End Sub
End Class
